package com.ssy.lingxi.contract.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.contract.model.vo.common.response.StatusItemVO;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 合同外部状态
 * @author 伍将
 * @date 2021/2/2
 * @version 2.0.0
 */
public enum ContractOuterStatusEnum {

    ALL(0, "所有状态"),
    TO_BE_SUBMIT_PARTY_B_SIGN_CONTRACT(1, "待提交乙方签订合同"),
    TO_BE_PARTY_B_SIGN_CONTRACT(2, "待乙方签订合同"),
    PARTY_B_DISAGREE_SIGN_CONTRACT(3, "乙方不同意签订合同"),
    TO_BE_PARTY_A_SIGN_CONTRACT(4, "待甲方签订合同"),
    PARTY_A_DISAGREE_SIGN_CONTRACT(5, "甲方不同意签订合同"),
    COMPLETE_SIGN_CONTRACT(6, "已完成签约"),
    INVALID(7, "已作废"),
    STOP_USING(8, "已停用"),
    EXPIRE(9, "合同已到期");

    private final Integer code;
    private final String message;

    ContractOuterStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return LanguageHolder.getName(this.getClass(), this.code);
    }

    public static String getMessage(Integer code) {
        return Arrays.stream(ContractOuterStatusEnum.values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(ALL).getMessage();
    }

    /**
     * 获得所有状态项列表
     * @param excludeCodes 排除的code/不排除传null
     * @return
     */
    public static List<StatusItemVO> all(List<Integer> excludeCodes){
        Stream<ContractOuterStatusEnum> stream = Arrays.stream(ContractOuterStatusEnum.values());
        if(excludeCodes!=null&&excludeCodes.size()>0){
            stream=stream.filter(o->!excludeCodes.contains(o.getCode()));
        }
       return stream.map(o ->{
                StatusItemVO vo=new StatusItemVO();
                vo.setCode(o.getCode());
                vo.setMessage(o.getMessage());
                return vo;
       }).collect(Collectors.toList());
    }

    /**
     * 合同执行列表状态：
     *  已完成签约，已停用，合同已到期
     * @return
     */
    public static List<StatusItemVO> executeStatusList(){
        Stream<ContractOuterStatusEnum> stream = Stream.of(ContractOuterStatusEnum.COMPLETE_SIGN_CONTRACT,ContractOuterStatusEnum.STOP_USING,ContractOuterStatusEnum.EXPIRE);
        return stream.map(o ->{
            StatusItemVO vo=new StatusItemVO();
            vo.setCode(o.getCode());
            vo.setMessage(o.getMessage());
            return vo;
        }).collect(Collectors.toList());
    }
}
